<?php
class ContactsController extends Controller {
 
    var $components = array('Email');


    function send() {
        if(!empty($this->data)) {
			$this->Contact->set($this->data);
			if($this->Contact->validates()) 
			{
				//NEW EMAIL COMPONENT
				$Email = new CakeEmail();
				//$Email->config('gmail');
				$Email->config(array(
								'from' => array(
										$this->data['Contact']['email'] => $this->data['Contact']['name']),
								'to' => 'test@alhui.com',
								'host' => 'ssl://smtp.gmail.com',
								'port' => 465,
								'username' => 'test@alhui.com',
								'password' => '!Q2w3e4r5',
								'transport' => 'Smtp'
								));
				
				$Email->subject('Enquiry via Website');
				$Email->send($this->data['Contact']['message']);
				//$this->Session->setFlash('Your message has been sent.');
				$this->render('success');
			}
			else
				$this->render('index');
		/*
		Email Account Details
		url: m.alhui.com
		username: test@alhui.com
		password: !Q2w3e4r5
		*/
			/*
            if($this->Contact->validates()) {
                if(!empty($this->data['Contact']['company'])) {
                    $this->Email->from = $this->data['Contact']['company'] . ' - ' . $this->data['Contact']['name'] . ' <' . $this->data['Contact']['email'] . '>';
                } else {
                    $this->Email->from = $this->data['Contact']['name'] . ' <' . $this->data['Contact']['email'] . '>';
                }
                $this->Email->to = 'lana.sawan@live.com';
                $this->Email->subject = 'Enquiry';
                $this->Email->send($this->data['Contact']['message']);
                $this->Session->setFlash('Your message has been sent.');
                // Display the success.ctp page instead of the form again
                $this->render('success');
            } else {
                $this->render('index');
            }
			*/
        }
    }
 
    function index() {
        // Placeholder for index. No actual action here, everything is submitted to the send function.
    }
 
	function success() {
	
	}
}
?>